
#include "msg_zs.h"
#include "client_mgr.h"
#include "frontend_service.h"

extern NLNET::CMessage        msgout;
extern NLNET::CCallbackServer *Clients;

using namespace FES;
using namespace NLNET;
using namespace DEF;

void cbBuildSucess ( NLNET::CMessage& msgin, const std::string &serviceName, NLNET::TServiceId serviceId )
{
	DEF::UID id;
	msgin.serial(id);
	CClient* pClient = ClientMgr.findClient(id);

	if(pClient==NULL)	{return;}

	uint32 time = 0;
	DEF::BUILD_ID bid;
	uint8 x;
	uint8 y;

	msgin.serial(time);
	msgin.serial(bid);
	msgin.serial(x);
	msgin.serial(y);

	msgout.clear();
	msgout.setType( "BS" );
	msgout.serial(time);
	msgout.serial(bid);
	msgout.serial(x);
	msgout.serial(y);

	Clients->send( msgout, pClient->con );
}

void cbBuildFail ( NLNET::CMessage& msgin, const std::string &serviceName, NLNET::TServiceId serviceId )
{
	DEF::UID id;
	msgin.serial(id);
	CClient* pClient = ClientMgr.findClient(id);

	if(pClient==NULL)	{return;}

	msgout.clear();
	msgout.setType("BF");
	Clients->send( msgout, pClient->con );
}

void cbRemoveBuildSucess ( NLNET::CMessage& msgin, const std::string &serviceName, NLNET::TServiceId serviceId )
{
	DEF::UID id;
	msgin.serial(id);
	CClient* pClient = ClientMgr.findClient(id);

	if(pClient==NULL)	{return;}

	uint32 time = 0;
	DEF::BUILD_ID bid;
	uint8 x;
	uint8 y;

	msgin.serial(time);
	msgin.serial(bid);
	msgin.serial(x);
	msgin.serial(y);

	msgout.clear();
	msgout.setType( "RBS" );
	msgout.serial(time);
	msgout.serial(bid);
	msgout.serial(x);
	msgout.serial(y);

	Clients->send( msgout, pClient->con );
}

void cbRemoveBuildFail ( NLNET::CMessage& msgin, const std::string &serviceName, NLNET::TServiceId serviceId )
{
	DEF::UID id;
	msgin.serial(id);
	CClient* pClient = ClientMgr.findClient(id);

	if(pClient==NULL)	{return;}

	msgout.clear();
	msgout.setType("RBF");
	Clients->send( msgout, pClient->con );
}


void cbClientLogout ( CMessage& msgin, const std::string &serviceName, NLNET::TServiceId serviceId )
{
	UID    id;
	msgin.serial(id);

	ClientMgr.disconnect(id);
	ClientMgr.removeClient(id);
	CMessage        msgout("LOGOUT_OK");
	msgout.serial(id);
	NLNET::CUnifiedNetwork::getInstance()->send ( serviceId, msgout );
}






